#ifndef QQ_CHAT_MESSAGE_MODEL
#define QQ_CHAT_MESSAGE_MODEL

#include <qabstractitemmodel.h>
#include <qcontiguouscache.h>

#include "core/QQConfig.h"

class QQChatMessageModel : public QAbstractListModel
{
	Q_OBJECT
public:
	explicit QQChatMessageModel(QObject* parent = nullptr);
	~QQChatMessageModel();
	void addMessage(QQChatMessage* message);
	void addMessages(QList<QQChatMessage*> messages);
	void addTextMessage(long id, QQMessageSenderType senderType, QQMessageSendType sendType, const QString& name, const QString& avatar, const QString& text);
	void addImageMessage(long id, QQMessageSenderType senderType, QQMessageSendType sendType, const QString& name, const QString& avatar, const QString& image);
	void addFileMessage(long id, QQMessageSenderType senderType, QQMessageSendType sendType, const QString& name, const QString& avatar, const QString& file);
	void addVoiceMessage(long id, QQMessageSenderType senderType, QQMessageSendType sendType, const QString& name, const QString& avatar, const QString& voice);
	void addVideoMessage(long id, QQMessageSenderType senderType, QQMessageSendType sendType, const QString& name, const QString& avatar, const QString& video);
	void addUrlMessage(long id, QQMessageSenderType senderType, QQMessageSendType sendType, const QString& name, const QString& avatar, const QString& url);
	void addMixMessage(long id, QQMessageSenderType senderType, QQMessageSendType sendType, const QString& name, const QString& avatar, const QString& mix);

	QQChatMessage* getMessage(long id);
	void clearMessage();

	int rowCount(const QModelIndex& parent = QModelIndex()) const override;
	QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
private:
	void addBaseMessage(long id, QQMessageSenderType senderType, QQMessageSendType sendType, const QString& name, const QString& avatar, const QString& content, QQMessageType type);
private:
	QContiguousCache<QQChatMessage*> mMessages;
};

#endif // QQ_CHAT_MESSAGE_MODEL
